﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL;
using System.Web.Services;
namespace blog.UserControl
{
    public partial class PostList : System.Web.UI.UserControl
    {
        public int thepostid;
        public Model.Post thepost;

        public void setid(int id)
        {
            this.thepostid = id;
        }
        public void setpost(Model.Post post)
        {
            this.thepost = post;
        }
        [WebMethod]
        public string getid()
        {
            return this.thepostid.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.thepostid.ToString()!="")
            {

                Dictionary<string, string> mypost = BAL.DoPost.getpost(thepostid);
                labpostid.Text = mypost["postid"].ToString();
                string url = "../Posts/ShowPost.aspx?postid=" + labpostid.Text.ToString();
                HyperLink link = new HyperLink();
                link.NavigateUrl = url;
                link.Text = mypost["postname"].ToString();

                labpostname.Controls.Add(link);
                //labpostname.Text = mypost["postname"].ToString();


                labpostcontent.Text = mypost["postcontent"].ToString();
                labpostdate.Text = mypost["postdate"].ToString();
                labpostuser.Text = mypost["postuser"].ToString();
                // Button1.Text = this.thepostid.ToString();
            }
            else if (this.thepost!= null)
            {
                labpostcontent.Text = thepost.postcontent;
                labpostid.Text = thepost.postid;
                string url = "../Posts/ShowPost.aspx?postid=" + labpostid.Text.ToString();
                HyperLink link = new HyperLink();
                link.NavigateUrl = url;
                link.Text = thepost.postname.ToString();
                labpostname.Controls.Add(link);
                labpostdate.Text = thepost.posttime;
                labpostuser.Text = thepost.postusername;
            }
        }
    }
}